package com.useeinfo.oa.modules.inspection.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.oa.common.utils.ResultUtil.ResultDto;
import com.useeinfo.oa.common.utils.ResultUtil.ResultUtil;
import com.useeinfo.oa.modules.base.enums.AuditTypeEnum;
import com.useeinfo.oa.modules.inspection.dao.InsAuditOrderDao;
import com.useeinfo.oa.modules.inspection.entity.InsAuditOrder;
import com.useeinfo.oa.modules.inspection.entity.InspectionOrder;
import com.useeinfo.oa.modules.maintaining.entity.AuditOrder;
import com.useeinfo.oa.modules.maintaining.entity.MaintainOrder;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class InsAuditOrderBiz extends CrudBiz<InsAuditOrderDao, InsAuditOrder> {

    /**
     * 保存审批记录
     * @param inspectionOrder
     * @param systemUser
     * @param pass
     * @param reason
     * @param auditTypeEnum
     * @param level
     * @return
     */
    public ResultDto saveOrUpdate(InspectionOrder inspectionOrder, SystemUser systemUser, boolean pass, String reason, AuditTypeEnum auditTypeEnum, int level){
        InsAuditOrder insAuditOrder = new InsAuditOrder();
        insAuditOrder.setCreateDate(new Date());
        insAuditOrder.setAuditTypeEnum(auditTypeEnum);
        insAuditOrder.setAuditDate(new Date());
        insAuditOrder.setLevel(level);
        insAuditOrder.setAuditUser(systemUser);
        insAuditOrder.setPass(pass);
        insAuditOrder.setEnterprise(inspectionOrder.getEnterprise());
        insAuditOrder.setReason(reason);
        insAuditOrder.setInspectionOrder(inspectionOrder);
        if(!pass){
            insAuditOrder.setEffective(false);
        }
        dao.add(insAuditOrder);
        return ResultUtil.success();
    }
}
